package io.terminus.spzx.pay.configuration;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import io.terminus.spzx.pay.properties.AlipayProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author lichunlong lcl253137@alibaba-inc.com
 * @Desc 支付宝配置类
 * @Date 2025-01-04
 */
@Configuration
@RequiredArgsConstructor
public class AlipayConfiguration {

    private final AlipayProperties alipayProperties;

    @Bean
    @ConditionalOnMissingBean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(alipayProperties.getAlipayUrl(),
                alipayProperties.getAppId(),
                alipayProperties.getAppPrivateKey(),
                AlipayProperties.format,
                AlipayProperties.charset,
                alipayProperties.getAlipayPublicKey(),
                AlipayProperties.sign_type);
    }
}
